<?php

class Ext_Video_Show_Build
{
    protected $_videoId;
    
    protected $_hosts = array('youku');
    
    public function __construct($videoId)
    {
        $this->_videoId = $videoId;
    }
    
    public function photo()
    {
        $_videoRow = App_Model_DbTable_Video::getInstance()->getRowById($this->_videoId);
        if(!$_videoRow){
            return "";
        }
        
        if(!$_imageId = $_videoRow['imageId']){
            return "";
        }
        
        return new Ext_Image_Show($_imageId);
    }
    
    public function flash()
    {
        $_videoRow = App_Model_DbTable_Video::getInstance()->getRowById($this->_videoId);
        if(!$_videoRow){
            return "";
        }
        
        if(!$_host = $_videoRow['host']){
            return "";
        }
        
        if(!$_siteVideoId = $_videoRow['videoId']){
            return "";
        }
        
        $_hostAdapter = '';
        for($i=0;$i<count($this->_hosts);$i++)
        {
            if(false !== strpos($_host, $this->_hosts[$i]))
            {
                $_hostAdapter = $this->_hosts[$i];
                break;
            }
        }
        if(!$_hostAdapter)
        {
            return "";
        }
        
        $classname = "Ext_Video_Show_Adapter_".ucfirst($_hostAdapter);
        if(!class_exists( $classname ))
        {
            require_once 'Ext/Video/Exception.php';
            throw new Ext_Video_Exception("Video show adapter '".$_hostAdapter."' not found.");
        }
        
        $_adapter = new $classname($_siteVideoId);
        
        return $_adapter->flash();
    }
}
